package com.audaque.springboot.foshanupload.web.mbdemo.crud.mapper;

import java.util.List;

import com.audaque.springboot.foshanupload.web.mbdemo.crud.domain.User;
import com.audaque.springboot.foshanupload.web.mbdemo.crud.query.UserQueryObject;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;



public interface UserAnnoMapper {
	//注解的方式配置不能和xml中的配置重复，注解方式配置(了解即可)
	//id，parameterType，resultType不用配置，因为方法已经显示了
	@Insert("insert into user(username,password,age) values (#{username},#{password},#{age})")
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="id")
	public void add(User t);
	@Update("update user set username=#{username},password=#{password},age=#{age} where id=#{id}")
	public void update(User t);
	/**select id as u_id,username as u_username,password ad u_password,age as u_age from user where id=#{id}
	当数据库查询出来的字段(u_username)和需要封装对象中的属性名(username)不一致的情况下,使用resultType是不可行的(这个是基于同名匹配规则),
	需要应用到resultMap来映射数据库字段和对象属性名之间的关系,解决方法：添加<resultMap>标签  ,resulMap="user_resultMap" */
	//不可复用
	@Results({
		@Result(column="u_id",property="id"),
		@Result(column="u_username",property="username"),
		@Result(column="u_password",property="password"),
		@Result(column="u_age",property="age")
	})
	@Select("select * from user where id=#{id}")
	public User get(Long id);
	@Select("select * from user")
	public List<User> list();
	@Delete("delete from user where id=#{id}")
	public void delete(Long id);
	public Long queryByConditionCount(UserQueryObject qo);
	public List<User> queryByCondition(UserQueryObject qo);

}
